home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / amigae.sept.archive / 000048_crash!prg.oxfor…d.ac.uk!m88jrh_Tue, 21 Sep 93 03:06:57 PST.msg (.txt) < prev    next >
LaTeX Document  |  1993-11-02  |  6KB  |  171 lines

  1. Received: by bkhouse.cts.com (V1.16/Amiga)
  2.     id AA00000; Tue, 21 Sep 93 03:06:57 PST
  3. Received: from sun2.nsfnet-relay.ac.uk by crash.cts.com with smtp
  4.     (Smail3.1.28.1 #18) id m0of2mx-0000NmC; Tue, 21 Sep 93 01:09 PDT
  5. Received: from ecs.oxford.ac.uk (ecs.ecs) by prg.oxford.ac.uk id AA00945;
  6.           Tue, 21 Sep 93 09:08:45 +0100
  7. Received: from ecs.ox.ac.uk (booth8.ecs) by ecs.oxford.ac.uk (4.1/ecs.1) 
  8.           id AA08915; Tue, 21 Sep 93 09:10:29 BST
  9. Received: by ecs.ox.ac.uk (4.1/ecs2.0) id AA01140; Tue, 21 Sep 93 09:09:41 BST
  10. Via: uk.ac.oxford.prg; Tue, 21 Sep 1993 09:09:10 +0100
  11. Date: Tue, 21 Sep 93 09:09:41 BST
  12. Message-Id: <9309210809.AA01140@booth8.ecs.ox.ac.uk>
  13. From: m88jrh@ecs.oxford.ac.uk
  14. To: amigae@bkhouse.cts.com
  15. Subject: A little E program
  16.   Dear All,
  17.   I've written a little program which someone else on this planet may find
  18. useful.  It's not very pretty but (I think) it works.  Basically, it's for
  19. people who have a version of TeX, like me, which doesn't decide what format
  20. file to use from the command name it is invoked with (like the Unix version
  21. does).  For example, if you make a hard link to 'virtex' called 'latex' the
  22. 'lplain' format file will be used.  Frustrated I set about making my TeX
  23. do the same. 
  24.   The program can be run from Workbench or the CLI (and it does different
  25. things...).  If run from the Workbench by itself it will invoke an interactive
  26. session of TeX, LaTeX or any other kind of TeX you have by looking at the
  27. name of the Workbench file.  The command names TeX and LaTeX get translated
  28. to format files 'plain' and 'lplain' respectively, any other name is taken to
  29. be the format name.
  30.   If run with arguments from the CLI or Workbench, it will investigate each
  31. file's icon (if it exists) for a 'DOTEXFMT' tooltype. This can be 'LATEX',
  32. 'TEX', or a format file name (like 'sliplain' or 'plain').  Otherwise it
  33. looks through the first 20 lines to find a line which begins '\documentstyle'
  34. or a comment '% latex' or '% tex'.  These decide the format used.  Failing
  35. all this normal TeX is run (the 'plain' format).
  36.   I use this program in conjunction with ToolManager (2.1) to have only one
  37. icon on the dock which does LaTeX or TeX according to the file.  You can also
  38. use it as the default tool for a TeX/LaTeX file.
  39.   Notice the use of the ReadArgs template 'FILE/M' to get standard arguments
  40. (like C's argv stuff) for the CLI, and the SystemTagList function to spawn
  41. asynchronous tasks.  Also, I've used StringF which Wouter omitted from the
  42. 2.1b documentation!
  43.    Let me know if you tidy it up or fix it!
  44. MODULE 'workbench/startup', 'workbench/workbench',
  45.        'icon', 'dos/dostags', 'dos/dos'
  46. CONST NUMARGS=1024
  47. DEF y=11
  48. PROC main()
  49.   DEF i, wb:PTR TO wbstartup, args:PTR TO wbarg, olddir,
  50.       templ, rdargs=NIL, arglist[NUMARGS]:LIST
  51.   iconbase:=OpenLibrary('icon.library', 33)
  52.   IF wb:=wbmessage
  53.     IF iconbase=NIL
  54.       CleanUp(10)
  55.     ENDIF
  56.     args:=wb.arglist
  57.     IF wb.numargs<>1
  58.       args++
  59.       FOR i:=2 TO wb.numargs
  60.         IF args[].lock
  61.           olddir:=CurrentDir(args[].lock)
  62.           dofile(args[].name++)
  63.           CurrentDir(olddir)
  64.         ELSE
  65.           dofile(args[].name++)
  66.         ENDIF
  67.       ENDFOR
  68.     ELSE
  69.       interact(args[].name)
  70.     ENDIF
  71.   ELSE
  72.     IF iconbase=NIL
  73.       WriteF('Can''t open icon.library\n')
  74.       CleanUp(10)
  75.     ENDIF
  76.     templ:='FILE/M'
  77.     rdargs:=ReadArgs(templ,arglist,NIL)
  78.     IF rdargs
  79.       IF arglist AND (arglist:=arglist[])
  80.         WHILE arglist[]
  81.           dofile(arglist[]++)
  82.         ENDWHILE
  83.       ENDIF
  84.       FreeArgs(rdargs)
  85.     ENDIF
  86.   ENDIF
  87.   IF iconbase THEN CloseLibrary(iconbase)
  88. ENDPROC
  89. PROC dofile(file)
  90.   DEF handle=NIL, dobj:PTR TO diskobject, fmt=NIL, 
  91.       sysline[256]:STRING, con=NIL, tool, i=0
  92.   handle:=Open(file, OLDFILE)
  93.   IF handle
  94.     IF dobj:=GetDiskObject(file)
  95.       IF tool:=FindToolType(dobj.tooltypes, 'DOTEXFMT')
  96.         LowerStr(tool)
  97.         IF StrCmp(tool, 'tex', ALL)
  98.           fmt:='plain'
  99.         ELSEIF StrCmp(tool, 'latex', ALL)
  100.           fmt:='lplain'
  101.         ELSEIF tool[]
  102.           fmt:=tool
  103.         ENDIF
  104.       ENDIF
  105.     ENDIF
  106.     IF fmt=NIL
  107.       WHILE (i++<20) AND (ReadStr(handle, sysline)<>-1)
  108.         IF StrCmp(sysline, '\\documentstyle', STRLEN)
  109.           fmt:='lplain'
  110.         ELSE
  111.           LowerStr(sysline)
  112.           IF StrCmp(sysline, '% latex', ALL)
  113.             fmt:='lplain'
  114.           ELSEIF StrCmp(sysline, '% tex', ALL)
  115.             fmt:='plain'
  116.           ENDIF
  117.         ENDIF
  118.       ENDWHILE
  119.       IF fmt=NIL
  120.         fmt:='plain'
  121.       ENDIF
  122.     ENDIF
  123.     Close(handle)
  124.     StringF(sysline, 'con:0/\d/640/94/DoTeX - \s/CLOSE/WAIT', y, file)
  125.     IF con:=Open(sysline, NEWFILE)
  126.       StringF(sysline, 'tex:bin/virtex &\s \s', fmt, file)
  127.       SystemTagList(sysline, [SYS_INPUT, NIL, SYS_OUTPUT, con,
  128.                               SYS_ASYNCH, TRUE, NIL])
  129.       y:=y+11
  130.       IF y>106 THEN y:=11
  131.     ENDIF
  132.     IF dobj THEN FreeDiskObject(dobj)
  133.   ELSEIF wbmessage=NIL
  134.     WriteF('File "\s" does not exist\n', file)
  135.   ENDIF
  136. ENDPROC
  137. PROC interact(file)
  138.   DEF name[128]:STRING, sysline[256]:STRING, fmt, handle, pos, found
  139.   pos:=InStr(file, ':', 0)
  140.   IF pos=-1
  141.     pos:=0
  142.   ELSE
  143.     INC pos
  144.   ENDIF
  145.   WHILE (found:=InStr(file, '/', pos))<>-1
  146.     pos:=found+1
  147.   ENDWHILE
  148.   MidStr(name, file, pos, ALL)
  149.   StringF(sysline, 'CON:0/11/640/94/DoTeX -- \s running/CLOSE/WAIT', name)
  150.   IF handle:=Open(sysline, NEWFILE)
  151.     LowerStr(name)
  152.     IF StrCmp(name, 'latex', ALL)
  153.       fmt:='lplain'
  154.     ELSEIF StrCmp(name, 'tex', ALL)
  155.       fmt:='plain'
  156.     ELSE
  157.       fmt:=name
  158.     ENDIF
  159.     StringF(sysline, 'tex:bin/virtex &\s', fmt)
  160.     SystemTagList(sysline, [SYS_INPUT, handle, SYS_OUTPUT, handle,
  161.                             SYS_ASYNCH, FALSE, NIL])
  162.     Close(handle)
  163.   ENDIF
  164. ENDPROC
  165. -----
  166.    _____  _
  167.      /   / |    /  /
  168.     /   /__/   /__/      Jason R. Hulance
  169.    /   /\     /  /   <m88jrh@uk.ac.oxford.ecs>
  170. |_/ . /  \ . /  / .
  171.